package cheme.ProcessEditor;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.Viewport;

public class ChemeViewport extends Viewport
{
	List<ViewportListener> listeners = new ArrayList<ViewportListener>();
	
	/**
	 * 
	 */
	public ChemeViewport()
	{
		super();
	}

	/**
	 * @param setting
	 */
	public ChemeViewport(boolean setting)
	{
		super(setting);
	}

	void addViewportListener(ViewportListener listener)
	{
		listeners.add(listener);
	}
	
	void removeViewportListener(ViewportListener listener)
	{
		listeners.remove(listener);
	}
		
	
	@Override
	public void setViewLocation(int x, int y)
	{
		int xDelta = x - getHorizontalRangeModel().getValue();
		int yDelta = y - getVerticalRangeModel().getValue();
		
		for(ViewportListener listener : listeners)
		{
			listener.ViewportChanged(xDelta, yDelta);
		}
		
		super.setViewLocation(x, y);
	}
}
